﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace SBLib.Common.StringKS
{
   public class StringFuncKS
    {

       /// <summary>
       /// Characters only
       /// </summary>
       /// <param name="textValue">text</param>
       /// <returns></returns>
        public static bool ValidateAlphabetOnly(string textValue)
        {
            bool valid = false;

            try
            {
                if (textValue.Trim().Length > 0)
                {
                    string regexPattern = @"^[a-zA-Z\s]+$";

                    Regex re = new Regex(regexPattern, RegexOptions.IgnoreCase);
                    valid = re.IsMatch(textValue.Trim());
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

            return valid;
        }


        /// <summary>
        /// Match string against RegexPattern
        /// </summary>
        /// <param name="AnyText">Pass any text</param>
        /// <param name="RegexPattern">Pass RegexPattern</param>
        /// <returns></returns>
        public static bool isMatch(string AnyText, string RegexPattern)
        {
            bool valid = false;

            try
            {

                if (AnyText.Trim().Length > 0)
                {
                    Regex re = new Regex(RegexPattern, RegexOptions.IgnoreCase);
                    valid = re.IsMatch(AnyText.Trim());
                }
            }
            catch (Exception)
            {
                return false;
            }

            return valid;
        }


        /// <summary>
        /// Email validation
        /// </summary>
        /// <param name="prmEmail"></param>
        /// <returns></returns>
        public static bool ValidateEmail(string email)
        {
            bool valid = false;

            try
            {

                if (email.Trim().Length > 0)
                {
                    string regexPattern = @"^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.(ad|aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z][a-z])|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$";

                    Regex re = new Regex(regexPattern, RegexOptions.IgnoreCase);
                    valid = re.IsMatch(email.Trim());
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

            return valid;
        }

    }
}
